<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=contract_nei','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=contract_nei','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_number" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>文件名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">业务归属</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_gui_unit_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" name="gofuer" id="gofuer" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程负责人联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="gofutel" id="gofutel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>签章状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>签章类型</label>
                        <div class="layui-input-block">
                            <select id="qiantype" name="qiantype" lay-filter="qiantype" ></select>
                            <p class="error" id="qiantype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">劳务分包服务费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="ratefu" id="ratefu" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税款保证金费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rateshui" id="rateshui" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">是否提供进项票</label>
                        <div class="layui-input-block">
                            <select id="ispiao" name="ispiao" lay-filter="ispiao" >
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            gofuer: {required: true},
            gofutel: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            gofuer: {required: "请输入"},
            gofutel: {required: "请输入"},
        }
    });


    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();



        facade.ajax({type: 'get', url: ask_contract_nei_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;


                $("#name").val(data.name);
                $("#gofuer").val(data.gofuer);
                $("#gofutel").val(data.gofutel);
                $("#ratefu").val(data.ratefu);
                $("#rateshui").val(data.rateshui);
                $("#ispiao").val(data.ispiao);
                $("#explain").val(data.explain);

                var engininfo = res.data.engininfo;
                if(engininfo){
                    set_choose_btn('enginid',engininfo.id,engininfo.name);

                    $('#engin_number').val(engininfo.number);
                    $('#engin_gui_unit_name').val(engininfo.gui_unit_name);
                }




                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(data.state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else{
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }
                }
                $("#state").html(state_str);

                var qiantype_str = '<option value="">请选择</option>';
                var qiantype = res.data.qiantype;
                for (var key in qiantype){
                    if(data.qiantype == qiantype[key]){
                        qiantype_str += '<option value="'+qiantype[key]+'" selected>'+qiantype[key]+'</option>';
                    }else{
                        qiantype_str += '<option value="'+qiantype[key]+'">'+qiantype[key]+'</option>';
                    }
                }
                $("#qiantype").html(qiantype_str);


                initParseMoney();
                public_upload_file_load('upload_files', res.data.files);
                render_from();
                render_date();
            }
        });


        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('select(qiantype)', function(data){
            if(data.value == ''){
                $('#qiantype_error').show().text('请选择');
                $('#qiantype_error').parent().find('input').addClass('select_error');
            }else{
                $('#qiantype_error').hide();
                $('#qiantype_error').parent().find('input').removeClass('select_error');
            }
        });



        form.on('submit(add)', function(data){
            parseMoney(data);

            data.field.enginid = get_choose_val('enginid');
            var validRes = $("#commentForm").valid();

            formValid('enginid');
            if(data.field.enginid == undefined || !data.field.enginid){
                validRes = false;
            }

            if(data.field.state == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(data.field.qiantype == ''){
                $('#qiantype_error').show().text('请选择');
                $('#qiantype_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#qiantype_error').hide();
                $('#qiantype_error').parent().find('input').removeClass('select_error');
            }

            if(!validRes){return false;}





            data.field.id = param_id;
            data.field.files = public_upload_file_value('upload_files');
            data = parseMoney(data);


            facade.ajax({url: ask_contract_nei_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });
            return false;
        });

    });



</script>
</body>
</html>
